package com.youlu.campus.admin.wechat;

import com.youlu.campus.common.base.RestResult;
import com.youlu.campus.common.base.RestResultBuilder;
import com.youlu.campus.entity.WechatMerchantConfig;
import com.youlu.campus.entity.wechat.WechatMerchantConfigDMLVo;
import com.youlu.campus.entity.wechat.WechatMerchantConfigVo;
import com.youlu.campus.service.wechat.WechatMerchantConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信商户号配置管理
 *
 * @Description: WechatMerchantConfigController
 * @Date 2025/6/20
 * @author: su
 */
@RestController
@RequestMapping(value = "/wechat/merchant-config")
public class WechatMerchantConfigController {

    @Autowired
    private WechatMerchantConfigService service;


    /**
     * 分页获取列表
     *
     * @param param
     * @return
     */
    @PostMapping("/list")
    public RestResult list(@RequestBody WechatMerchantConfigVo param) {
        Page<WechatMerchantConfig> page = service.findByPage(param);
        return RestResultBuilder.builder().success().data(page).build();
    }

    /**
     * 查询详情
     *
     * @param param
     * @return
     */
    @GetMapping("/detail")
    public RestResult detail(WechatMerchantConfig param) {
        WechatMerchantConfig config = service.findById(param.getId());
        if (config == null) {
            return RestResultBuilder.builder().failure().message("请求参数错误").build();
        }
        return RestResultBuilder.builder().success().data(config).build();

    }

    /**
     * 获取手机验证码
     *
     * @return
     */
    @GetMapping("/getPhoneCode")
    public RestResult getPhoneCode() {
        service.sendSmsMsg();
        return RestResultBuilder.builder().success().build();
    }

    /**
     * 保存
     *
     * @param param
     * @return
     */
    @PostMapping("/save")
    public RestResult save(@RequestBody WechatMerchantConfigDMLVo param) {
        return service.save(param);
    }

    /**
     * 删除
     *
     * @param param
     * @return
     */
    @PostMapping("/delete")
    public RestResult delete(@RequestBody WechatMerchantConfigDMLVo param) {
        return service.delete(param);
    }

}
